const{getMusicHttp}=require('../../utils/http')

Page({
  data: {
   musics:[],
   limit:20
  },
  
  onLoad:function (options){
    // console.log(options)
    var musics=[];
    var limit=this.data.limit; 
    getMusicHttp(limit).then(res=>{
      console.log(res.data.albums);
      var res=res.data.albums;
      res.forEach(item=>{
        var {name,picUrl,artist}=item;
        musics.push({
          name,
          picUrl,
          singer:artist.name
        })
        this.setData({
          musics
        })
        /* var singer=item.program.mainSong.name

        var{category,name,picUrl}=item.program.radio;

        musics.push({category,name,picUrl,singer})

        this.setData({
          musics
        }) */
      })
    })
    
    
  },
  
  /* onReachBottom(){
    // console.log("1");
    var limit=this.data.limit;
    limit+=20;
   
    getMusicHttp(limit).then(res=>{
      var musicss=this.data.musics;
      musicss=[]
      // console.log(res)
      var list=res.data.toplist;
      list.forEach(item=>{
        var singer=item.program.mainSong.name;
        var{category,name,picUrl}=item.program.radio;
        musicss.push({category,name,picUrl,singer})
   
      })
      this.setData({
        musics:[...musicss],
        limit
      })
    })
    
  } */

  onReachBottom(){
    // console.log("1")
    var limit=this.data.limit;
    limit+=20;

    getMusicHttp(limit).then(res=>{
      var music=this.data.musics;
      music=[];
      console.log(res)
      var list=res.data.albums;
      list.forEach(item=>{
        var {name,picUrl,artist}=item;
        music.push({
          name,
          picUrl,
          singer:artist.name
        })
        
      })
      this.setData({
        musics:music,
        limit

      })
    })
  }
})
